package com.ruoyi.web.controller.erpbase;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Inventorys;
import com.ruoyi.system.service.IInventorysService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 库存Controller
 * 
 * @author he
 * @date 2025-09-17
 */
@Api(tags = "库存接口")
@RestController
@RequestMapping("/system/inventorys")
public class InventorysController extends BaseController
{
    @Autowired
    private IInventorysService inventorysService;

    /**
     * 查询库存列表
     */
    @ApiOperation("查询库存信息")
    @PreAuthorize("@ss.hasPermi('system:inventorys:list')")
    @GetMapping("/list")
    public TableDataInfo list(Inventorys inventorys)
    {
        startPage();
        List<Inventorys> list = inventorysService.selectInventorysList(inventorys);
        return getDataTable(list);
    }

    /**
     * 导出库存列表
     */
    @ApiOperation("导出库存信息")
    @PreAuthorize("@ss.hasPermi('system:inventorys:export')")
    @Log(title = "库存", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Inventorys inventorys)
    {
        List<Inventorys> list = inventorysService.selectInventorysList(inventorys);
        ExcelUtil<Inventorys> util = new ExcelUtil<Inventorys>(Inventorys.class);
        util.exportExcel(response, list, "库存数据");
    }

    /**
     * 获取库存详细信息
     */
    @ApiOperation("库存详细信息")
    @PreAuthorize("@ss.hasPermi('system:inventorys:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(inventorysService.selectInventorysById(id));
    }

    /**
     * 新增库存
     */
    @ApiOperation("新增库存信息")
    @PreAuthorize("@ss.hasPermi('system:inventorys:add')")
    @Log(title = "库存", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Inventorys inventorys)
    {
        return toAjax(inventorysService.insertInventorys(inventorys));
    }

    /**
     * 修改库存
     */
    @ApiOperation("修改库存信息")
    @PreAuthorize("@ss.hasPermi('system:inventorys:edit')")
    @Log(title = "库存", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Inventorys inventorys)
    {
        inventorys.setUpdateUserId(SecurityUtils.getUserId());
        inventorys.setUpdateUserName(SecurityUtils.getUsername());
        return toAjax(inventorysService.updateInventorys(inventorys));
    }

    /**
     * 刷新库存
     */
    @ApiOperation("刷新库存信息")
    @PreAuthorize("@ss.hasPermi('system:inventorys:refresh')")
    @Log(title = "刷新库存", businessType = BusinessType.UPDATE)
    @PostMapping("/refreshInventory")
    public AjaxResult refreshInventory(@RequestBody Inventorys inventorys)
    {
        return toAjax(inventorysService.refreshInventory(inventorys));
    }

    /**
     * 删除库存
     */
    @ApiOperation("删除库存信息")
    @PreAuthorize("@ss.hasPermi('system:inventorys:remove')")
    @Log(title = "库存", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(inventorysService.deleteInventorysByIds(ids));
    }
}
